package com.h3bpm.kumhosunny.crm.controller.customercontact;/**
 * @Auther: Administrator
 * @Date: 2019/10/17 16:43
 * @Description:
 */

import OThinker.H3.Controller.ControllerBase;
import com.alibaba.fastjson.JSONObject;
import com.h3bpm.kumhosunny.common.utils.SqlUtil;
import data.DataRow;
import data.DataTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName:
 * @Description: 描述
 *
 * @author WJQ
 * @version V1.0
 * @Date
 */
@Controller
@RequestMapping("/Portal/CRM/CustomerProfileUnCar")
public class CustomerProfileUnCarController extends ControllerBase {

    private static Logger log = LoggerFactory.getLogger(CustomerProfileUnCarController.class);
    private  final String ONE="1";

    private  final String TOW="2";
    @Override
    public String getFunctionCode() {
        return null;
    }
    @RequestMapping("/getUnCarList")
    @ResponseBody
    public JSONObject getBoList(String clientData, String state ,String start){
        log.info("移动端非汽车客户档案接口==================clientData="+clientData);
        JSONObject result= new JSONObject();
        String userId =  getUserValidator().getUser().getCode();
        try {

        String sql = "SELECT  b.`Name` AS man,c.ObjectID,c.customerName,c.customerStatus,c.mainProducts FROM ( " +
                "SELECT CreatedTime,ObjectID,appDatas,customerName,customerStatus,mainProducts,CreatedByParentId,salesman FROM i_customerprofile  " +
                ") c " +
                "LEFT JOIN  ot_user b ON c.salesman = b.ObjectID  where 1=1 ";
        if(clientData != null &&  !"".equals(clientData)){
            sql="SELECT  b.`Name` AS man,c.ObjectID,c.customerName,c.customerStatus,c.mainProducts FROM ( " +
                    "SELECT CreatedTime,ObjectID,appDatas,customerName,customerStatus,mainProducts,CreatedByParentId,salesman FROM i_customerprofile WHERE  " +
                    " customerName like '%"+clientData+"%' OR customerStatus like '%"+clientData+"%' or mainProducts like '%"+clientData+"%' OR salesman LIKE '%"+clientData+"%' " +
                    ") c  LEFT JOIN  ot_user b ON c.salesman = b.ObjectID where 1=1 ";
        }
         DataTable table = null;
            if(ONE.equals(state)){
                sql += " and  c.appDatas  like '%" + userId + "%'  ORDER BY c.CreatedTime DESC ";
            }
            sql+="    limit  "+start+",10 ";

            table = SqlUtil.doQuery(sql);

        List<Map<String ,String >> list =new ArrayList<Map<String ,String > >();
        if(table!=null && table.getEntityRows()!=null && table.getEntityRows().size()>0){
            for( DataRow dataRow :  table.getEntityRows()) {
                Map<String, String> customerMap = new HashMap<String, String>(16);
                String objectId=dataRow.getString("ObjectID");
                String customerName=dataRow.getString("customerName");
                String customerStatus=dataRow.getString("customerStatus");
                String mainProducts=dataRow.getString("mainProducts");
                String exclusiveSalesman=dataRow.getString("man");
                customerMap.put("customerName",customerName);
                customerMap.put("customerStatus",customerStatus);
                customerMap.put("mainProducts",mainProducts);
                customerMap.put("ObjectId",objectId);
                customerMap.put("salesman",exclusiveSalesman);
                list.add(customerMap);
            }
        }
        result.put("data",list);
        result.put("status","200");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/skipSoloNotCarList")
    public String skipSoloList(){

        return "redirect:/Portal/Mobile/kumhosunny/customerProfileUnCar.html?state=1";
    }


    @RequestMapping("/skipUnitNotCarList")
    public String skipUnitLinkmanList(){

        return "redirect:/Portal/Mobile/kumhosunny/customerProfileUnCar.html?state=2";
    }

}
